﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace ttg_internal.utils
{
    /// <summary>
    /// Base class for eny entries in logger.
    /// </summary>
    public abstract class PerfElement : IEnumerable<PerfElement>
    {
        #region Properties

        private string _name;

        /// <summary>
        /// Returns name of this record. Cannot be null. Should be used as short description.
        /// Note: this name is not unique.
        /// </summary>
        public string Name
        {
            get
            {
                return _name;
            }
        }

        private string _description;

        /// <summary>
        /// Returns full description of the test. Cannot be null.
        /// </summary>
        public string Description
        {
            get
            {
                return _description;
            }
        }

        private List<PerfElement> _childs;

        /// <summary>
        /// Returns associated subrecords.
        /// </summary>
        public List<PerfElement> Childs
        {
            get
            {
                return _childs;
            }
        }

        #endregion

        protected PerfElement(string Name, string Description)
        {
            this._name = Name;
            this._description = Description;
            this._childs = new List<PerfElement>();
        }

        /// <summary>
        /// Stores current element and its childs to xml.
        /// Do not forget about childs storing!
        /// </summary>
        public abstract void SaveToXml(XmlDocument doc, XmlNode parent);

        /// <summary>
        /// Stores cerrent element and its childs to html.
        /// Do not forget about childs storing!
        /// </summary>
        /// <param name="?">buffer for result</param>
        public abstract void SaveToHtml(StringBuilder html);

        #region IEnumerable Members

        public IEnumerator<PerfElement> GetEnumerator()
        {
            return Childs.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Childs.GetEnumerator();
        }

        #endregion
    }
}
